package com.tuanda.app.customviewdemo.cavans;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.RectF;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.View;

/**
 * Created by LiDongduo on 2018/9/19.
 */
public class DrawProgressView extends View {

    private Paint mPaint;

    public DrawProgressView(Context context) {
        this(context,null);
    }

    public DrawProgressView(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs,0);
    }

    public DrawProgressView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }

    private void init() {
        mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
        mPaint.setColor(Color.BLACK);
        mPaint.setStyle(Paint.Style.STROKE);
        mPaint.setStrokeWidth(20);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        canvas.drawCircle(120,100,50,mPaint);

        RectF rectF = new RectF(70,50,170,150);

        mPaint.setColor(Color.YELLOW);
        mPaint.setStrokeCap(Paint.Cap.ROUND);
        canvas.drawArc(rectF,0,140,false,mPaint);

        mPaint.setColor(Color.BLUE);
        canvas.drawArc(rectF,-35,35,false,mPaint);

        mPaint.setColor(Color.GREEN);
        canvas.drawArc(rectF,-70,35,false,mPaint);

        mPaint.setColor(Color.RED);
        canvas.drawArc(rectF,-90,20,false,mPaint);
    }
}
